//
//  TemplateManageTableCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/16.
//

#import "TemplateManageTableCell.h"
@interface TemplateManageTableCell ()
@property (nonatomic ,strong) UILabel * mmlab;
@property (nonatomic ,strong) UILabel * namelab;
@property (nonatomic ,strong) UILabel * DescriptionLab;
@property (nonatomic ,strong) UIButton * btn;
@property (nonatomic ,assign) BOOL isGG;


@end
@implementation TemplateManageTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * backview = [UIView new];
    backview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:backview];
    [self addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(kwt(5));
        make.bottom.offset(kwt(-5));
    }];
    
    
    UILabel * mmlab = [DTKTool labelWithText:@"模版" andFont:kCFont(17) andTextColor:UIColor.whiteColor];
    self.mmlab = mmlab;
    mmlab.textAlignment = NSTextAlignmentCenter;
    mmlab.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(60), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#0967FF") endColor:KcolorHex(@"#64A2FF")];
    [backview addSubview:mmlab];
    [DTKTool YJ:kwt(5) andView:mmlab];
    [mmlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.offset(kwt(12));
        make.width.offset(kwt(60));
        make.height.offset(kwt(26));
    }];
    
    UILabel * namelab = [DTKTool labelWithText:@"--" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    self.namelab = namelab;
    [backview addSubview:namelab];
    [namelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mmlab.mas_right).offset(kwt(6));
        make.centerY.equalTo(mmlab);
        make.right.offset(kwt(-10));
    }];
    UILabel * DescriptionLab = [DTKTool labelWithText:@"--" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    self.DescriptionLab = DescriptionLab;
    DescriptionLab.numberOfLines = 0;
    [backview addSubview:DescriptionLab];
    [DescriptionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(48));
        make.right.offset(kwt(-12));
    }];
    
    UIButton * btn = [UIButton buttonWithType:0];
    self.btn = btn;
    btn.backgroundColor = KcolorHex(@"#F5F7FF");
    btn.addNormalColor(KcolorHex(@"#0967FF")).addFont(kCFont(16)).addTarget(self,@selector(btnclick));
    [DTKTool YJBK:kwt(18) andView:btn andWidth:0.5 andColor:KcolorHex(@"#0967FF")];
    [backview addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.bottom.offset(kwt(-14));
        make.width.offset(kwt(190));
        make.height.offset(kwt(36));
    }];
    
    
    
}
-(void)setModel:(TemplateManageModel *)model{
    _model = model;
    self.namelab.text = model.name;
    self.DescriptionLab.text = model.Description;
    
}
-(void)setIndex:(NSInteger)index andIsGG:(BOOL)isGG{
    self.isGG = isGG;
    self.mmlab.text = [NSString stringWithFormat:@"模版%ld",(long)index];
    self.btn.addNormalText(isGG?@"创建模版":@"修改");
}
- (void)btnclick{
    if(self.isGG){
        if(self.openGGBlock){
            self.openGGBlock(self.model);
        }
    } else {
        if(self.openGRBlock){
            self.openGRBlock(self.model);
        }
    }
}

@end
